package com.shengzai.mapreduce.groupby;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 求出对各班级中学生的总分进行排序，并且求出前一名和后一名总分的差距，并按照如下格式写出：
 * 	文科一班	1500100308	黄初夏	女	628	    33
 * 	文科一班	1500100875	马向南	女	595 	15
 */
public class MapGroupBy extends Mapper<LongWritable, Text,Text,Text> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split("\t");
        String[] info = split[1].split(",");
        String clazz = info[3];
        //1500100007	尚孤风,23,女,文科六班,418
        //Sid   name    sex     score
        String values = split[0] + "," + info[0] + "," + info[2] + "," + info[4];
        context.write(new Text(clazz),new Text(values));
    }


}
